package com.cc.crm.utils;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @Title: PropertiesUtil.java 
 * @Package com.kz.utils 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author 新梦想IT.陈超
 * @date 2017年12月29日 上午10:43:07 
 * @version V1.0
 *
 *
 * md5 散列算法
 *  abc（明文）---md5加密---->128位/16字节的字符串
 *
 *  abc(明文)---加盐+明文--->md5加密--->128为字符串
 */
public class PropertiesUtil {

    final static Logger logger = LogManager.getLogger(PropertiesUtil.class.getName());

    private static Properties props;

    static {
        String fileName = "ndcrm.properties";
        props = new Properties();
        try {
            props.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName),"UTF-8"));
            //props.load(new InputStreamReader(ClassLoader.getSystemResourceAsStream(fileName))); //getClassLoader().getResourceAsStream(fileName),"UTF-8"));
        } catch (IOException e) {
            logger.error("配置文件读取异常",e);
        }
    }

    public static String getProperty(String key){
        String value = props.getProperty(key.trim());
        if(StringUtils.isBlank(value)){
            return null;
        }
        return value.trim();
    }

    public static String getProperty(String key,String defaultValue){

        String value = props.getProperty(key.trim());
        if(StringUtils.isBlank(value)){
            value = defaultValue;
        }
        return value.trim();
    }

    //测试
    public static void main(String[] args) {
        System.out.println(PropertiesUtil.getProperty("password.salt"));
    }


}
